<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="http://rdcloud-web.oss-cn-beijing.aliyuncs.com/web/img/rddms.ico">
    <title>登录</title>
    <!-- Bootstrap core CSS -->
    <link href="${ctxPath}/vendor/bootstrap-4.0.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctxPath}/assets/css/signin.css" rel="stylesheet">
    <script type="text/javascript" src="${ctxPath}/vendor/jquery/jquery-3.2.1.min.js"></script>
  </head>

  <body class="text-center">
    <form class="form-signin">
      <img class="mb-4" src="https://getbootstrap.com/assets/brand/bootstrap-solid.svg" alt="" width="72" height="72">
      <h1 class="h3 mb-3 font-weight-normal">欢迎欢迎</h1>
      <label for="inputEmail" class="sr-only">用户名</label>
      <input type="email" id="inputEmail" class="form-control" placeholder="用户名" required autofocus>
      <label for="inputPassword" class="sr-only">密码</label>
      <input type="password" id="inputPassword" class="form-control" placeholder="密码" required>
       <p id='msg' class="mt-5 mb-3" style="font-color:red"></p>
      <div class="checkbox mb-3">
        <label>
          <input type="checkbox" value="remember-me"> 记住密码
        </label>
      </div>
      <button class="btn btn-lg btn-primary btn-block" type="button" onclick="login()" >登录</button>
      <p class="mt-5 mb-3 text-muted">&copy; 2017-2018</p>
    </form>
    
    <input type="hidden" id="basePath" value="${ctxPath}" />
  </body>
  <script>

  var basePath = $("#basePath").val();
  window.onload = function () {  
      if (window.parent.window != window) {  
          window.top.location = basePath+"/login.do";  
      }  
  }  
  
  
  function login(){
	   var inputEmail = $("#inputEmail").val();
	   var inputPassword = $("#inputPassword").val();
	   $.ajax({
	        type: "POST",
	        url: basePath+"/doLogin.do",
	        data: {'username': inputEmail, 'password': inputPassword},
	        datatype: "json", 
	        //请求异常回掉操作
	    	success: function(data){
	    		var obj = JSON.parse(data); //由JSON字符串转换为JSON对象
	    		console.log(obj);
        		if(obj.code =="200"){
        			 window.location=basePath+'/main.do';	
        		}else{
        			$("#msg").html(obj.msg);
        		}

        	}
	        
  });
  }
  </script>
</html>
